import axios from 'axios'
import store from '@/store'
import {
  actions as LoginActions
} from '@/components/Login'
import {
  message
} from 'antd'

export default function (token) {
  //  store.dispatch(LoginActions.saveInfo({
  //      cPhone: 123123,
  //      cPhoto: '',
  //      cUsername: 'qwe'
  //  }))
  //  return
  axios.get('/nuonuo/invoice/sso.action', {
    params: {
      token: token
    }
  }).then(res => {
    if (res.code === 'S0000') {
      const data = res.result.data;
      const userInfo = data && {
        cPhone: data.mobile,
        cPhoto: data.photo,
        cUsername: data.userName
      }
      store.dispatch(LoginActions.saveInfo(userInfo))
    } else {
      store.dispatch(LoginActions.signOut())
    }

  }).catch(error => {
    message.error('请求登录失败！');
    throw (error)
  })
}